package spring.DI.methodDI;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * 方法注入配置类：使用 @Lookup 注解实现（https://cloud.tencent.com/developer/article/1554037）
 *  默认情况下 @Lookup 根据返回类型查找 原型bean
 *
 * @author ME
 * @date   2019/2/26 19:06
 */
@Configuration
@ComponentScan("spring.DI.methodDI")
public class BeansConfig {

    @Bean
    public Animal animal() {
        return new Animal() {
            @Override
            public Dog createDog() {
                return dog01();
            }
        };
    }

    // 默认方法名为 beanName，@Bean 注解的 value会覆盖方法名
    @Bean("dog111")
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public Dog dog01() {
        return new Dog();
        // return null;
    }

}
